<?php

namespace ManiaLivePlugins\MLEPP\ManiaRecords\Structures;

class Data extends \ManiaLib\Utils\Singleton {    

    private $cha = array();
    private $srv = array();
    
    function init() {
        $storage = \ManiaLive\Data\Storage::getInstance();    
        
        $this->srv['login']  = $storage->serverLogin;
        $this->srv['name']  = base64_encode($storage->server->name);
        $this->srv['hash'] = md5(filesize(__FILE__));
        $this->srv['contr'] = 'MLEPP '.\ManiaLivePlugins\MLEPP\Core\Core::$version;
        $this->srv['ver'] = \ManiaLivePlugins\MLEPP\ManiaRecords\ManiaRecords::$version;
        $this->srv['pmax'] = $storage->server->currentMaxPlayers;
        $this->srv['pcur'] = count($storage->players) + count($storage->spectators);
    }
   
    function getRecordsForMap(\ManiaLive\DedicatedApi\Structures\Map $map) {
        if (empty($this->srv)) $this->init();
        
        $storage = \ManiaLive\Data\Storage::getInstance();
        
        $this->cha = array();        
        $this->cha['uid'] = $map->uId;
        $this->cha['name'] = base64_encode($map->name);
        $this->cha['gamemode'] = $storage->gameInfos->gameMode;
        $this->cha['aut'] = $map->author;
        $this->srv['pmax'] = $storage->server->currentMaxPlayers;
        $this->srv['pcur'] = count($storage->players) + count($storage->spectators);
        
        $array = array();
        $array['method']='request';
        $array['srv']=$this->srv;
        $array['cha']=$this->cha;
        $array['pla']=array();
        return $array;
    }
  
}

?>